// router/index.ts 文件

import {
  createRouter,
  createWebHashHistory,
  RouterOptions,
  Router,
  RouteRecordRaw,
} from "vue-router";
//由于router的API默认使用了类型进行初始化，内部包含类型定义，所以本文内部代码中的所有数据类型是可以省略的
//RouterRecordRaw是路由组件对象

import Layout from "@/layout/index.vue";

/* 
meta属性必填 里面所有字段必填
title 标题
icon 图标
hidden 是否在侧边栏隐藏
meta: { title: '文件', icon: 'files', hidden: true },
*/
const routes: RouteRecordRaw[] = [
  // 首页
  {
    path: "/index",
    name: "Index",
    component: () => import("@/views/index/index.vue"),
    meta: { title: "首页", icon: "star", hidden: true },
  },

  // 文件页
  {
    path: "/platform",
    component: Layout,
    redirect: "/platform/files",
    meta: { title: "文件", icon: "star", hidden: false },
    children: [
      {
        path: "files",
        name: "files",
        component: () => import("@/views/platform/base/files.vue"),
        meta: { title: "我的文件", icon: "star", hidden: false },
      },
      // 公开分享
      {
        path: "my-shared-items",
        name: "my-shared-items",
        component: import("@/views/platform/base/my-shared-items.vue"),
        meta: { title: "公开分享", icon: "star", hidden: false },
      },
      // 最近上传
      {
        path: "recent-upload",
        name: "recent-upload",
        component: () => import("@/views/platform/base/recent-uploads.vue"),
        meta: { title: "最近上传", icon: "star", hidden: false },
      },
      // 垃圾
      {
        path: "trash",
        name: "trash",
        component: () => import("@/views/platform/base/trash.vue"),
        meta: { title: "垃圾", icon: "star", hidden: false },
      },
    ],
  },

  // 简介页
  {
    path: "/profile",
    component: Layout,
    redirect: "/profile/account",
    meta: { title: "简介", icon: "star", hidden: false },
    children: [
      // 账号设定
      {
        path: "account",
        name: "account",
        component: () => import("@/views/profile/account.vue"),
        meta: { title: "账号", icon: "star", hidden: false },
      },
      // 安全性和API
      {
        path: "self-and-api",
        name: "self-and-api",
        component: () => import("@/views/profile/self.vue"),
        meta: { title: "安全性和API", icon: "star", hidden: false },
      },
      // 存储
      {
        path: "save",
        name: "save",
        component: () => import("@/views/profile/save.vue"),
        meta: { title: "存储", icon: "star", hidden: false },
      },
    ],
  },

  // 管理员设置页 只对管理员账号开放
  {
    path: "/admin",
    component: Layout,
    redirect: "/admin/dashboard",
    meta: { title: "设置", icon: "star", hidden: false },
    children: [
      // 仪表盘
      {
        path: "dashboard",
        name: "dashboard",
        component: () => import("@/views/admin/dashboard.vue"),
        meta: { title: "仪表盘", icon: "star", hidden: false },
      },
      // 用户
      {
        path: "user",
        name: "user",
        component: () => import("@/views/admin/user.vue"),
        meta: { title: "user", icon: "star", hidden: false },
      },
      // 设置
      {
        path: "setting",
        name: "setting",
        component: () => import("@/views/admin/setting.vue"),
        meta: { title: "设置", icon: "star", hidden: false },
      },
      // 页面
      {
        path: "page",
        name: "page",
        component: () => import("@/views/admin/page.vue"),
        meta: { title: "页面", icon: "star", hidden: false },
      },
    ],
  },

  // 登录
  {
    path: "/login",
    name: "Login",
    component: () => import("@/views/login/index.vue"),
    meta: { title: "登录", icon: "star", hidden: true },
  },
  // 注册
  {
    path: "/register",
    name: "Register",
    component: () => import("@/views/register/index.vue"),
    meta: { title: "注册", icon: "star", hidden: true },
  },
  // 忘记密码
  {
    path: "/forgottenPassword",
    name: "forgottenPassword",
    component: () => import("@/views/forgottenPassword/index.vue"),
    meta: { title: "忘记密码", icon: "star", hidden: true },
  },
  // 联系我们
  {
    path: "/contactUs",
    name: "ContactUs",
    component: () => import("@/views/contactUs/index.vue"),
    meta: { title: "联系我们", icon: "star", hidden: true },
  },
  // 条款服务
  {
    path: "/termsService",
    name: "TermsService",
    component: () => import("@/views/termsService/index.vue"),
    meta: { title: "条款服务", icon: "star", hidden: true },
  },
  // 隐私
  {
    path: "/privacyPolicy",
    name: "PrivacyPolicy",
    component: () => import("@/views/privacyPolicy/index.vue"),
    meta: { title: "隐私策略", icon: "star", hidden: true },
  },
  // cookie
  {
    path: "/cookiePolicy",
    name: "CookiePolicy",
    component: () => import("@/views/cookiePolicy/index.vue"),
    meta: { title: "cookie", icon: "star", hidden: true },
  },
];
// RouterOptions是路由选项类型
const options: RouterOptions = {
  history: createWebHashHistory(),
  routes,
};

// Router是路由对象类型
const router: Router = createRouter(options);

export default router;
